#include "FiveWin.ch"

static lRegistered := .f.

//----------------------------------------------------------------------------//

CLASS TBitmap FROM TControl

   DATA   cBitmap
   DATA   hBitmap

   METHOD New( nTop, nLeft, nBottom, nRight, cBitmap, oWnd ) CONSTRUCTOR
   METHOD Release()
   METHOD HandleEvent( nMsg, nWParam, nLParam )
   METHOD ReDefine( nId, cBitmap ) CONSTRUCTOR
   METHOD Paint()
   METHOD SetBMP( cBitmap )

ENDCLASS

//----------------------------------------------------------------------------//

METHOD New( nTop, nLeft, nBottom, nRight, cBitmap, oWnd ) CLASS TBitmap

   ::nTop    = nTop
   ::nLeft   = nLeft
   ::nBottom = nBottom 
   ::nRight  = nRight
   ::cBitmap = cBitmap
   ::hBitmap = LoadBitmap( GetResources(), cBitmap )
   ::nStyle  = nOR( WS_BORDER, WS_CHILD )

   if ! lRegistered
      ::Register( nOR( CS_VREDRAW, CS_HREDRAW, CS_GLOBALCLASS ) )
      lRegistered = .t.
   endif
   ::Create()

return

//----------------------------------------------------------------------------//

METHOD Release() CLASS TBitmap

   DeleteObject( ::hBitmap )
   Super:Release()

return

//----------------------------------------------------------------------------//

METHOD ReDefine( nId, cBitmap ) CLASS TBitmap

   ::nId     = nId
   ::cBitmap = cBitmap
   ::hBitmap = LoadBitmap( GetResources(), cBitmap )

   if ! lRegistered
      ::Register( nOR( CS_VREDRAW, CS_HREDRAW, CS_GLOBALCLASS ) )
      lRegistered = .t.
   endif

return

//----------------------------------------------------------------------------//

METHOD Paint() CLASS TBitmap

   ::GetDC()
   DrawBitmap( ::hDC, ::hBitmap, 0, 0 )
   ::ReleaseDC()

return

//----------------------------------------------------------------------------//

METHOD SetBMP( cBitmap ) CLASS TBitmap

   ::cBitmap = cBitmap
   DeleteObject( ::hBitmap )
   ::hBitmap = LoadBitmap( GetResources(), cBitmap )
   ::Refresh()

return

//----------------------------------------------------------------------------//

METHOD HandleEvent( nMsg, nWParam, nLParam ) CLASS TBitmap

   local nRet

   if nMsg == WM_PAINT
      ::BeginPaint()
      ::Paint()
      ::EndPaint()
      nRet = 0
   else
      nRet = Super:HandleEvent( nMsg, nWParam, nLParam )
   endif

return nRet

//----------------------------------------------------------------------------//
